{% extends 'base.html' %}

{% block head %}
    {% if not website %}
        <title>添加网站-在线不聊天</title>
    {% else %}
        <title>编辑网站-在线不聊天</title>
    {% endif %}

{% endblock %}

{% block content %}
<div class="simpleui-box simpleui-row">
    {% if not website %}
    <form method="POST" action="/websites" class="simpleui-form">

        <label class="simpleui-form-label">网站名称: </label><input type="text" name="name" autocomplete="off" required placeholder="请输入网站名称"><br>
        <label class="simpleui-form-label">网站URL: </label><input type="text" name="url" autocomplete="off" required placeholder="请输入网站URL"><br>
        <label class="simpleui-form-label">分类: </label><select name="sort_id">
            {% for sort in sorts %}
            <option value="{{ sort.id }}">{{ sort.name }}</option>
            {% endfor %}
        </select>
        <br>
        <label class="simpleui-form-label">备注: </label><input type="text" name="remark" autocomplete="off" required placeholder="请输入备注"><br>
        <div class="simpleui-input-block">
            <input type="submit" value="添加">
            <a href="/websites"><input type="button" value="取消"></a>
        </div>
    </form>

    {% else %}

    <form method="POST" class="simpleui-form">
        <input type="hidden" name="_method" value="PUT"><!--由于 form 表单不支持 put/delete , 这个使用参数欺骗-->
        <label class="simpleui-form-label">网站名称: </label><input type="text" name="name" value="{{ website.name }}" autocomplete="off" required
                                   placeholder="请输入网站名称"><br>
        <label class="simpleui-form-label">网站URL: </label><input type="text" name="url" value="{{ website.url }}" autocomplete="off" required
                                    placeholder="请输入网站URL"><br>
        <label class="simpleui-form-label">分类: </label><select name="sort_id">
            {% for sort in sorts %}
            <option value="{{ sort.id }}"
                    {% if sort.id == website.sort_id %} selected {% endif%}
            >{{ sort.name }}</option>
            {% endfor %}
        </select>
        <br>
        <label class="simpleui-form-label">备注: </label><input type="text" name="remark" value="{{ website.remark }}" autocomplete="off" required
                                 placeholder="请输入备注"><br>
        <div class="simpleui-input-block">
            <input type="submit" value="保存">
            <a href="/websites"><input type="button" value="取消"></a>
        </div>
    </form>
    {% endif %}
</div>
{% endblock %}
